home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / eev100r1.zip / POSTFIX.DOC < prev    next >
Text File  |  1993-04-01  |  4KB  |  121 lines

  1.      -------------------------------------------------------------------
  2.      POSTFIX.PAS (TP5.5/6.0) and POSTFIX.INC (TP3.0)
  3.      -------------------------------------------------------------------
  4.  
  5.      February 2, 1992:   Version 1.00, Revision 1
  6.  
  7.      - TP3.0 include files added
  8.      - supports TP3.0, TP5.5, and TP6.0
  9.  
  10.      December 28, 1991:  Version 1.00, Revision 0
  11.  
  12.      - original release for TP5.5 and TP6.0
  13.  
  14.      Written by: David J. Firth
  15.                  5665-A2 Parkville St.
  16.                  Columbus, OH 43229
  17.  
  18.      This unit provides an API for a postfix expression evaluator.
  19.  
  20.      Postfix is reverse polish notation (RPN), a notation for
  21.      expressions that is commonly used by Hewlett Packard calculators
  22.      and stack based languages like Forth.
  23.  
  24.      This evaluator supports the following functions:
  25.  
  26.      + - * / PI ABS ARCTAN COS LN EXP SQR SQRT
  27.  
  28.      Variables are supported also.  Any string of characters that
  29.      the evaluator finds that is not a number or an operator is
  30.      assumed to be a variable ID.  When a variable ID is found in
  31.      and expression, the variable's value is pushed onto the stack.
  32.  
  33.      Variable identifiers are passed around as strings of type Str20.
  34.  
  35.      The variable-related procedures are:
  36.  
  37.      -------------------------------------------------------------------
  38.  
  39.      procedure StoreVariable(VariableID:str20;MyValue:real);
  40.  
  41.      This procedure will store MyValue in the variable identified by
  42.      VariableID.  If the variable doesn't exist, it will be created.
  43.      If the variable does exist, the value will be updated.
  44.  
  45.      -------------------------------------------------------------------
  46.  
  47.      procedure ReadVariable(VariableID:str20;var MyValue:real;
  48.                             var MyError:boolean);
  49.  
  50.      This procedure will read the value of the variable identified by
  51.      VariableID.  If the variable doesn't exist, MyError will be true.
  52.  
  53.      -------------------------------------------------------------------
  54.  
  55.      procedure InitializeEE;
  56.  
  57.      This routine is present in POSTFIX.INC, the evaluator for
  58.      TP 3.0, only.
  59.  
  60.      This routine is used to initialize the stack and variables
  61.      linked list prior to evaluator use.  If you do not call this
  62.      routine, the evaluator will probably crash, since the stack
  63.      and linked list pointers could point to anywhere.
  64.  
  65.      In the TP5.5/6.0 version, POSTFIX.PAS, the unit initialization
  66.      code performs this function.
  67.      -------------------------------------------------------------------
  68.  
  69.      procedure DestroyList;
  70.  
  71.      The variables are stored in a singly linked list.  If your program
  72.      uses variables, you need to call this routine before you exit to
  73.      DOS.  Otherwise, the memory taken by the linked list will not be
  74.      given back.
  75.  
  76.      Likewise, the evaluator's stack is allocated on the heap.  This
  77.      routine will also destroy the stack (via the DestroyStack internal
  78.      procedure).
  79.  
  80.      -------------------------------------------------------------------
  81.  
  82.      Calculation results may either be stored in variables or returned
  83.      to the caller.  The following procedures should be used to call
  84.      the expression evaluator.
  85.  
  86.      -------------------------------------------------------------------
  87.  
  88.      procedure Calculate(MyFormula:string;
  89.                          var MyResult:real;
  90.                          var MyError:boolean);
  91.  
  92.      This procedure will evaluate an RPN expression, returning the
  93.      result is returned to the caller.
  94.  
  95.      MyError=false indentifies a successful evaluation.
  96.  
  97.      -------------------------------------------------------------------
  98.  
  99.      procedure CalcAndStore(MyFormula:string;
  100.                             StoreID:str20;
  101.                             var MyError:boolean);
  102.  
  103.      This procedure will evaluate an RPN expression, storing the
  104.      result in the variable identified by StoreID.
  105.  
  106.      MyError=false indentifies a successful evaluation.
  107.  
  108.      CalcAndStore calls Calculate for expression evaluation.
  109.  
  110.      -------------------------------------------------------------------
  111.  
  112.      I have tested this code using Turbo Debugger 2.0 and it seems
  113.      to work fine.  However, if you find a bug, please let me know.
  114.  
  115.      Your comments are welcome (and desired!). My E-Mail addresses
  116.      are:
  117.  
  118.      GEnie:     D.FIRTH
  119.      CIS:       76467,1734
  120.  
  121.